home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / mint / lib / mntlib44.zoo / mntlib / lattice / vfork.s < prev   
Text File  |  1993-10-12  |  2KB  |  87 lines

  1.     INCLUDE    inc.i
  2.     
  3. ;
  4. ; vfork for MiNT. Note that the return address must be popped off the stack,
  5. ; or else it could be clobbered by the child and the parent would be left
  6. ; returning to la-la land. Also note that MiNT guarantees that register a1
  7. ; will be preserved across a vfork() system call.
  8. ;
  9.  
  10.     FUDATA
  11. _store:        ds.l    32
  12.  
  13.     INFO
  14.     xref    ___mint        ; MiNT version kept here
  15.     xref    _errno
  16. L_vfsav:    dc.l    _store
  17.  
  18.     CODE
  19.     IF    _REGARG
  20.     xdef    @vfork
  21.     xref    @tfork
  22. @vfork:
  23.     ELSE
  24.     xdef    _vfork
  25.     xref    _tfork
  26. _vfork:
  27.     ENDC
  28.     
  29.     move.l    (sp)+,a1    ; save return address; this is important!
  30.     IF    _SHORT
  31.     tst.w    ___mint
  32.     ELSE
  33.     tst.l    ___mint
  34.     ENDC
  35.     beq.s    L_TOS        ; go do the TOS thing
  36.     move.w    #$113,-(sp)    ; push MiNT Pvfork() parameter
  37.     trap    #1        ; Vfork
  38.     addq.l    #2,sp
  39.     tst.l    d0        ; error??
  40.     bmi    L_err
  41.     jmp    (a1)        ; return
  42. L_TOS:
  43.     lea        L_vfsav,a0
  44.     movem.l    d2-d7/a1-a6,(a0)    ; save registers - in _store
  45.     IF    _REGARG
  46.     move.l    a0,d0
  47.     lea    L_newprog,a0
  48.     bsr    @tfork
  49.     ELSE
  50.     move.l    a0,-(sp)
  51.     pea    L_newprog
  52.     bsr    _tfork        ; tfork(L_newprog,*L_vfsav)
  53.     addq.l    #8,sp
  54.     ENDC
  55.     lea        L_vfsav,a0
  56.     movem.l    (a0),d2-d7/a1-a6    ; restore reggies
  57.     tst.l    d0        ; fork went OK??
  58.     bmi.s    L_err        ; no -- error
  59.     jmp    (a1)        ; return to caller
  60. L_err:
  61.     IF    _SHORT
  62.     neg.w    d0
  63.     move.w    d0,_errno
  64.     ELSE
  65.     neg.l    d0
  66.     move.l    d0,_errno    ; save error code in errno
  67.     ENDC
  68.     moveq.l    #-1,d0        ; return -1
  69.     jmp    (a1)        ; return
  70.  
  71. ;
  72. ; L_newprog: here is where the child starts executing,with argument
  73. ; L_vfsav. We restore registers,zero d0, and jump back to parent
  74. ;
  75.  
  76. L_newprog:
  77.     addq.l    #4,sp        ; pop useless return address
  78.     IF    _REGARG
  79.     move.l    d0,a0
  80.     ELSE
  81.     move.l    (sp)+,a0    ; get address of save area
  82.     ENDC
  83.     movem.l    (a0),d2-d7/a1-a6    ; restore reggies
  84.     moveq    #$0,d0        ; child always returns 0 from vfork
  85.     jmp    (a1)        ; back to caller, as child process
  86.     end
  87.